# SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

import torch
import random
import ttnn
import pytest

from typing import Optional, Tuple

from tests.ttnn.utils_for_testing import check_with_pcc, start_measuring_time, stop_measuring_time
from models.common.utility_functions import torch_random


TIMEOUT = 15  # longer timeout since permute calls transpose recursively
random.seed(0)

# Tensor<[1, 10]> self = ?
parameters = {
    "nightly": {
        "transpose_specs": [
            {"shape": [1, 16, 256, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 256, 64], "dim0": 2, "dim1": 3},
            {"shape": [1024, 1024], "dim0": -1, "dim1": -2},
            {"shape": [1024, 4096], "dim0": -1, "dim1": -2},
            {"shape": [2, 1024], "dim0": -1, "dim1": -2},
            {"shape": [4096, 1024], "dim0": -1, "dim1": -2},
            {"shape": [1024, 1024], "dim0": 0, "dim1": 1},
            {"shape": [1024, 4096], "dim0": 0, "dim1": 1},
            {"shape": [2, 1024], "dim0": 0, "dim1": 1},
            {"shape": [4096, 1024], "dim0": 0, "dim1": 1},
            {"shape": [1, 32, 12, 100], "dim0": -2, "dim1": -3},
            {"shape": [1, 10], "dim0": 0, "dim1": 1},
            {"shape": [1, 128], "dim0": 0, "dim1": 1},
            {"shape": [1, 512], "dim0": 0, "dim1": 1},
            {"shape": [1, 768], "dim0": 0, "dim1": 1},
            {"shape": [10, 128], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1008], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1024], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1280], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1512], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1536], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1664], "dim0": 0, "dim1": 1},
            {"shape": [1000, 1920], "dim0": 0, "dim1": 1},
            {"shape": [1000, 2016], "dim0": 0, "dim1": 1},
            {"shape": [1000, 2048], "dim0": 0, "dim1": 1},
            {"shape": [1000, 2208], "dim0": 0, "dim1": 1},
            {"shape": [1000, 2520], "dim0": 0, "dim1": 1},
            {"shape": [1000, 3024], "dim0": 0, "dim1": 1},
            {"shape": [1000, 3712], "dim0": 0, "dim1": 1},
            {"shape": [1000, 400], "dim0": 0, "dim1": 1},
            {"shape": [1000, 4096], "dim0": 0, "dim1": 1},
            {"shape": [1000, 440], "dim0": 0, "dim1": 1},
            {"shape": [1000, 512], "dim0": 0, "dim1": 1},
            {"shape": [1000, 672], "dim0": 0, "dim1": 1},
            {"shape": [1000, 7392], "dim0": 0, "dim1": 1},
            {"shape": [1000, 768], "dim0": 0, "dim1": 1},
            {"shape": [1000, 784], "dim0": 0, "dim1": 1},
            {"shape": [1000, 888], "dim0": 0, "dim1": 1},
            {"shape": [1000, 912], "dim0": 0, "dim1": 1},
            {"shape": [1024, 1024], "dim0": 0, "dim1": 1},
            {"shape": [1024, 128], "dim0": 0, "dim1": 1},
            {"shape": [1024, 2048], "dim0": 0, "dim1": 1},
            {"shape": [1024, 256], "dim0": 0, "dim1": 1},
            {"shape": [1024, 4096], "dim0": 0, "dim1": 1},
            {"shape": [1024, 512], "dim0": 0, "dim1": 1},
            {"shape": [1024, 576], "dim0": 0, "dim1": 1},
            {"shape": [10240, 1280], "dim0": 0, "dim1": 1},
            {"shape": [1152, 384], "dim0": 0, "dim1": 1},
            {"shape": [12, 3], "dim0": 0, "dim1": 1},
            {"shape": [12, 512], "dim0": 0, "dim1": 1},
            {"shape": [12, 64], "dim0": 0, "dim1": 1},
            {"shape": [128, 1024], "dim0": 0, "dim1": 1},
            {"shape": [128, 10], "dim0": 0, "dim1": 1},
            {"shape": [128, 128], "dim0": 0, "dim1": 1},
            {"shape": [128, 2048], "dim0": 0, "dim1": 1},
            {"shape": [128, 32], "dim0": 0, "dim1": 1},
            {"shape": [128, 4096], "dim0": 0, "dim1": 1},
            {"shape": [128, 512], "dim0": 0, "dim1": 1},
            {"shape": [128, 64], "dim0": 0, "dim1": 1},
            {"shape": [128, 784], "dim0": 0, "dim1": 1},
            {"shape": [128, 9216], "dim0": 0, "dim1": 1},
            {"shape": [1280, 1280], "dim0": 0, "dim1": 1},
            {"shape": [1280, 320], "dim0": 0, "dim1": 1},
            {"shape": [1280, 5120], "dim0": 0, "dim1": 1},
            {"shape": [1280, 768], "dim0": 0, "dim1": 1},
            {"shape": [1280, 960], "dim0": 0, "dim1": 1},
            {"shape": [1536, 1536], "dim0": 0, "dim1": 1},
            {"shape": [1536, 384], "dim0": 0, "dim1": 1},
            {"shape": [1536, 512], "dim0": 0, "dim1": 1},
            {"shape": [1536, 6144], "dim0": 0, "dim1": 1},
            {"shape": [1536, 768], "dim0": 0, "dim1": 1},
            {"shape": [16, 512], "dim0": 0, "dim1": 1},
            {"shape": [160, 160], "dim0": 0, "dim1": 1},
            {"shape": [160, 640], "dim0": 0, "dim1": 1},
            {"shape": [16384, 4096], "dim0": 0, "dim1": 1},
            {"shape": [192, 192], "dim0": 0, "dim1": 1},
            {"shape": [192, 384], "dim0": 0, "dim1": 1},
            {"shape": [192, 768], "dim0": 0, "dim1": 1},
            {"shape": [196, 384], "dim0": 0, "dim1": 1},
            {"shape": [2, 1024], "dim0": 0, "dim1": 1},
            {"shape": [2, 1], "dim0": 0, "dim1": 1},
            {"shape": [2, 768], "dim0": 0, "dim1": 1},
            {"shape": [2048, 128], "dim0": 0, "dim1": 1},
            {"shape": [2048, 2048], "dim0": 0, "dim1": 1},
            {"shape": [2048, 256], "dim0": 0, "dim1": 1},
            {"shape": [2048, 512], "dim0": 0, "dim1": 1},
            {"shape": [2048, 8192], "dim0": 0, "dim1": 1},
            {"shape": [21843, 768], "dim0": 0, "dim1": 1},
            {"shape": [2304, 768], "dim0": 0, "dim1": 1},
            {"shape": [24, 512], "dim0": 0, "dim1": 1},
            {"shape": [250002, 768], "dim0": 0, "dim1": 1},
            {"shape": [250880, 1536], "dim0": 0, "dim1": 1},
            {"shape": [256, 1024], "dim0": 0, "dim1": 1},
            {"shape": [256, 1280], "dim0": 0, "dim1": 1},
            {"shape": [256, 160], "dim0": 0, "dim1": 1},
            {"shape": [256, 2048], "dim0": 0, "dim1": 1},
            {"shape": [256, 256], "dim0": 0, "dim1": 1},
            {"shape": [256, 32], "dim0": 0, "dim1": 1},
            {"shape": [256, 512], "dim0": 0, "dim1": 1},
            {"shape": [256, 64], "dim0": 0, "dim1": 1},
            {"shape": [256, 768], "dim0": 0, "dim1": 1},
            {"shape": [256, 80], "dim0": 0, "dim1": 1},
            {"shape": [2560, 320], "dim0": 0, "dim1": 1},
            {"shape": [256008, 1024], "dim0": 0, "dim1": 1},
            {"shape": [288, 96], "dim0": 0, "dim1": 1},
            {"shape": [3, 12], "dim0": 0, "dim1": 1},
            {"shape": [3, 512], "dim0": 0, "dim1": 1},
            {"shape": [30000, 128], "dim0": 0, "dim1": 1},
            {"shape": [3072, 1024], "dim0": 0, "dim1": 1},
            {"shape": [3072, 768], "dim0": 0, "dim1": 1},
            {"shape": [3129, 1536], "dim0": 0, "dim1": 1},
            {"shape": [32, 128], "dim0": 0, "dim1": 1},
            {"shape": [32, 32], "dim0": 0, "dim1": 1},
            {"shape": [32, 512], "dim0": 0, "dim1": 1},
            {"shape": [320, 1280], "dim0": 0, "dim1": 1},
            {"shape": [320, 320], "dim0": 0, "dim1": 1},
            {"shape": [320, 768], "dim0": 0, "dim1": 1},
            {"shape": [32128, 1024], "dim0": 0, "dim1": 1},
            {"shape": [32128, 512], "dim0": 0, "dim1": 1},
            {"shape": [32128, 768], "dim0": 0, "dim1": 1},
            {"shape": [384, 128], "dim0": 0, "dim1": 1},
            {"shape": [384, 1536], "dim0": 0, "dim1": 1},
            {"shape": [384, 196], "dim0": 0, "dim1": 1},
            {"shape": [384, 384], "dim0": 0, "dim1": 1},
            {"shape": [384, 512], "dim0": 0, "dim1": 1},
            {"shape": [384, 768], "dim0": 0, "dim1": 1},
            {"shape": [384, 96], "dim0": 0, "dim1": 1},
            {"shape": [3840, 1280], "dim0": 0, "dim1": 1},
            {"shape": [4, 192], "dim0": 0, "dim1": 1},
            {"shape": [4, 256], "dim0": 0, "dim1": 1},
            {"shape": [4, 512], "dim0": 0, "dim1": 1},
            {"shape": [4096, 1024], "dim0": 0, "dim1": 1},
            {"shape": [4096, 128], "dim0": 0, "dim1": 1},
            {"shape": [4096, 16384], "dim0": 0, "dim1": 1},
            {"shape": [4096, 25088], "dim0": 0, "dim1": 1},
            {"shape": [4096, 4096], "dim0": 0, "dim1": 1},
            {"shape": [4608, 1536], "dim0": 0, "dim1": 1},
            {"shape": [50257, 768], "dim0": 0, "dim1": 1},
            {"shape": [50272, 512], "dim0": 0, "dim1": 1},
            {"shape": [512, 1024], "dim0": 0, "dim1": 1},
            {"shape": [512, 128], "dim0": 0, "dim1": 1},
            {"shape": [512, 2048], "dim0": 0, "dim1": 1},
            {"shape": [512, 256], "dim0": 0, "dim1": 1},
            {"shape": [512, 2], "dim0": 0, "dim1": 1},
            {"shape": [512, 384], "dim0": 0, "dim1": 1},
            {"shape": [512, 512], "dim0": 0, "dim1": 1},
            {"shape": [512, 768], "dim0": 0, "dim1": 1},
            {"shape": [5120, 1280], "dim0": 0, "dim1": 1},
            {"shape": [5120, 640], "dim0": 0, "dim1": 1},
            {"shape": [51200, 1024], "dim0": 0, "dim1": 1},
            {"shape": [51865, 768], "dim0": 0, "dim1": 1},
            {"shape": [576, 192], "dim0": 0, "dim1": 1},
            {"shape": [6, 512], "dim0": 0, "dim1": 1},
            {"shape": [6144, 1536], "dim0": 0, "dim1": 1},
            {"shape": [64, 128], "dim0": 0, "dim1": 1},
            {"shape": [64, 12], "dim0": 0, "dim1": 1},
            {"shape": [64, 256], "dim0": 0, "dim1": 1},
            {"shape": [64, 64], "dim0": 0, "dim1": 1},
            {"shape": [640, 1280], "dim0": 0, "dim1": 1},
            {"shape": [640, 160], "dim0": 0, "dim1": 1},
            {"shape": [640, 2560], "dim0": 0, "dim1": 1},
            {"shape": [640, 640], "dim0": 0, "dim1": 1},
            {"shape": [640, 768], "dim0": 0, "dim1": 1},
            {"shape": [65024, 4544], "dim0": 0, "dim1": 1},
            {"shape": [768, 1280], "dim0": 0, "dim1": 1},
            {"shape": [768, 128], "dim0": 0, "dim1": 1},
            {"shape": [768, 1536], "dim0": 0, "dim1": 1},
            {"shape": [768, 192], "dim0": 0, "dim1": 1},
            {"shape": [768, 256], "dim0": 0, "dim1": 1},
            {"shape": [768, 3072], "dim0": 0, "dim1": 1},
            {"shape": [768, 768], "dim0": 0, "dim1": 1},
            {"shape": [784, 128], "dim0": 0, "dim1": 1},
            {"shape": [8, 512], "dim0": 0, "dim1": 1},
            {"shape": [8192, 2048], "dim0": 0, "dim1": 1},
            {"shape": [92, 192], "dim0": 0, "dim1": 1},
            {"shape": [92, 256], "dim0": 0, "dim1": 1},
            {"shape": [9216, 128], "dim0": 0, "dim1": 1},
            {"shape": [96, 384], "dim0": 0, "dim1": 1},
            {"shape": [96, 96], "dim0": 0, "dim1": 1},
            {"shape": [1, 1, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 1, 16, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 1, 256, 32], "dim0": -1, "dim1": -2},
            {"shape": [1, 1, 300, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 1, 6, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 1, 7, 64], "dim0": -2, "dim1": -1},
            {"shape": [1, 1, 8, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 10, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 10, 16, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 10, 8, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 1024, 196], "dim0": 1, "dim1": 2},
            {"shape": [1, 1024, 256], "dim0": 1, "dim1": 2},
            {"shape": [1, 1024, 640], "dim0": 1, "dim1": 2},
            {"shape": [1, 1024, 8, 80], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 1, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 12, 10, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 10, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 10, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 12, 12, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 12, 64], "dim0": 2, "dim1": 1},
            {"shape": [1, 12, 14, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 14, 64], "dim0": 2, "dim1": 1},
            {"shape": [1, 12, 1500, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 16, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 16, 64], "dim0": 2, "dim1": 3},
            {"shape": [1, 12, 197, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 2, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 12, 201, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 24, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 25, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 4, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 45, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 46, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 50, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 12, 7, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 9, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 12, 9, 64], "dim0": 2, "dim1": 1},
            # {"shape": [1, 12, "s0 + 1", 64], "dim0": 3, "dim1": 2},
            # {"shape": [1, 12, "s10 + 1", 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 1200, 1280], "dim0": 1, "dim1": 2},
            {"shape": [1, 128, 16384], "dim0": 1, "dim1": 2},
            {"shape": [1, 128, 4800], "dim0": 1, "dim1": 2},
            {"shape": [1, 1280, 1200], "dim0": 1, "dim1": 2},
            {"shape": [1, 1370, 1, 3, 1280], "dim0": 0, "dim1": -2},
            {"shape": [1, 1370, 1280], "dim0": 1, "dim1": 0},
            {"shape": [1, 144, 768], "dim0": 1, "dim1": 2},
            {"shape": [1, 15, 6, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 1500, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 1, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 16, 10, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 10, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 16, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 19, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 197, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 2, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 16, 256, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 5, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 59, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 16, 6, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 9, 128], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 9, 128], "dim0": 2, "dim1": 1},
            {"shape": [1, 16, 9, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 16, 9, 64], "dim0": 2, "dim1": 1},
            # {"shape": [1, 16, "s0 + 1", 64], "dim0": 3, "dim1": 2},
            # {"shape": [1, 16, "s10 + 1", 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 160, 1024], "dim0": 1, "dim1": 2},
            {"shape": [1, 16384, 128], "dim0": 1, "dim1": 2},
            {"shape": [1, 19, 16, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 192, 1344], "dim0": 1, "dim1": 2},
            {"shape": [1, 19200, 256], "dim0": 1, "dim1": 2},
            {"shape": [1, 196, 768], "dim0": 1, "dim1": 2},
            {"shape": [1, 197, 1, 3, 1024], "dim0": 0, "dim1": -2},
            {"shape": [1, 197, 1, 3, 768], "dim0": 0, "dim1": -2},
            {"shape": [1, 197, 1024], "dim0": 1, "dim1": 0},
            {"shape": [1, 197, 768], "dim0": 1, "dim1": 0},
            {"shape": [1, 2, 256, 32], "dim0": -1, "dim1": -2},
            {"shape": [1, 2, 300, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 2048, 300], "dim0": 1, "dim1": 2},
            {"shape": [1, 24, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 24, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [1, 24, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [1, 24, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [1, 24, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [1, 24576], "dim0": 1, "dim1": 0},
            {"shape": [1, 256, 1024], "dim0": 1, "dim1": 2},
            {"shape": [1, 256, 19200], "dim0": 1, "dim1": 2},
            {"shape": [1, 256, 256], "dim0": 1, "dim1": 2},
            {"shape": [1, 256, 4096], "dim0": 1, "dim1": 2},
            {"shape": [1, 256, 8, 160], "dim0": 1, "dim1": 2},
            {"shape": [1, 3, 1445, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 300, 2048], "dim0": 1, "dim1": 2},
            {"shape": [1, 32, 16, 96], "dim0": 1, "dim1": 2},
            {"shape": [1, 32, 16384], "dim0": 1, "dim1": 2},
            {"shape": [1, 32, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [1, 32, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [1, 32, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [1, 32, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [1, 320, 1200], "dim0": 1, "dim1": 2},
            {"shape": [1, 4, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 4096, 256], "dim0": 1, "dim1": 2},
            {"shape": [1, 4096, 8, 40], "dim0": 1, "dim1": 2},
            {"shape": [1, 4150, 192], "dim0": 1, "dim1": 2},
            {"shape": [1, 4800, 512], "dim0": 1, "dim1": 2},
            {"shape": [1, 5, 256, 32], "dim0": -1, "dim1": -2},
            {"shape": [1, 5, 300, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 50, 1, 3, 1024], "dim0": 0, "dim1": -2},
            {"shape": [1, 50, 1, 3, 768], "dim0": 0, "dim1": -2},
            {"shape": [1, 50, 1024], "dim0": 1, "dim1": 0},
            {"shape": [1, 50, 12, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 50, 768], "dim0": 1, "dim1": 0},
            {"shape": [1, 512, 300], "dim0": 1, "dim1": 2},
            {"shape": [1, 512, 4800], "dim0": 1, "dim1": 2},
            {"shape": [1, 59, 16, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 6, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 6, 1, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 6, 15, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 6, 15, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 6, 17, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 6, 2, 64], "dim0": 3, "dim1": 2},
            # {"shape": [1, 6, "s0 + 1", 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 64, 19200], "dim0": 1, "dim1": 2},
            {"shape": [1, 64, 4096], "dim0": 1, "dim1": 2},
            {"shape": [1, 64, 8, 160], "dim0": 1, "dim1": 2},
            {"shape": [1, 64, 9, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 64, 9, 64], "dim0": 2, "dim1": 1},
            {"shape": [1, 640, 1024], "dim0": 1, "dim1": 2},
            {"shape": [1, 7, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 7, 71, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 768, 192], "dim0": 1, "dim1": 2},
            {"shape": [1, 768, 196], "dim0": 1, "dim1": 2},
            {"shape": [1, 768, 49], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 1, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 8, 10, 64], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 10, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 8, 1024, 80], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 2, 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 8, 2048, 32], "dim0": -1, "dim1": -2},
            {"shape": [1, 8, 256, 160], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 256, 32], "dim0": -1, "dim1": -2},
            {"shape": [1, 8, 300, 64], "dim0": -1, "dim1": -2},
            {"shape": [1, 8, 4096, 40], "dim0": 1, "dim1": 2},
            {"shape": [1, 8, 64, 160], "dim0": 1, "dim1": 2},
            # {"shape": [1, 8, "s0 + 1", 64], "dim0": 3, "dim1": 2},
            {"shape": [1, 80, 96], "dim0": 1, "dim1": 2},
            {"shape": [1, 9, 8, 160], "dim0": 1, "dim1": 2},
            {"shape": [1, 9, 8, 40], "dim0": 1, "dim1": 2},
            {"shape": [1, 9, 8, 80], "dim0": 1, "dim1": 2},
            {"shape": [1, 96, 80], "dim0": 1, "dim1": 2},
            {"shape": [1, 96, 80], "dim0": 2, "dim1": 1},
            {"shape": [100, 8, 32], "dim0": 0, "dim1": 1},
            {"shape": [12, 1, 64], "dim0": 1, "dim1": 2},
            {"shape": [12, 2, 64], "dim0": 1, "dim1": 2},
            {"shape": [12, 24, 64], "dim0": 0, "dim1": 1},
            {"shape": [12, 24, 64], "dim0": 1, "dim1": 2},
            {"shape": [12, 50, 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s0 + 1", 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s10 + 1", 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s2 + 1", 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s4 + 1", 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s6 + 1", 64], "dim0": 1, "dim1": 2},
            # {"shape": [12, "s8 + 1", 64], "dim0": 1, "dim1": 2},
            {"shape": [1370, 1, 1280], "dim0": 1, "dim1": 0},
            {"shape": [1370, 16, 80], "dim0": 0, "dim1": 1},
            {"shape": [16, 19, 64], "dim0": 1, "dim1": 2},
            {"shape": [16, 59, 64], "dim0": 1, "dim1": 2},
            {"shape": [16, 6, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [16, 6, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [16, 6, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [16, 6, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [16, 60, 64], "dim0": 1, "dim1": 2},
            {"shape": [16, 7, 64], "dim0": 1, "dim1": 2},
            {"shape": [16, 8, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [16, 8, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [16, 8, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [16, 8, 64, 32], "dim0": 1, "dim1": 2},
            # {"shape": [16, "s10 + 1", 64], "dim0": 1, "dim1": 2},
            {"shape": [197, 1, 1024], "dim0": 1, "dim1": 0},
            {"shape": [197, 1, 768], "dim0": 1, "dim1": 0},
            {"shape": [197, 12, 64], "dim0": 0, "dim1": 1},
            {"shape": [197, 16, 64], "dim0": 0, "dim1": 1},
            {"shape": [2, 7, 8, 64], "dim0": 1, "dim1": 2},
            {"shape": [2, 8, 7, 64], "dim0": 1, "dim1": 2},
            {"shape": [24, 12, 24], "dim0": 0, "dim1": 1},
            {"shape": [24, 24, 64], "dim0": -2, "dim1": -1},
            {"shape": [262, 768], "dim0": 0, "dim1": 1},
            {"shape": [4, 12, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [4, 12, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [4, 12, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [4, 12, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [4, 16, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [4, 16, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [4, 16, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [4, 16, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [50, 1, 1024], "dim0": 1, "dim1": 0},
            {"shape": [50, 1, 768], "dim0": 1, "dim1": 0},
            {"shape": [50, 12, 64], "dim0": 0, "dim1": 1},
            {"shape": [50, 16, 64], "dim0": 0, "dim1": 1},
            {"shape": [6, 100, 1, 256], "dim0": 1, "dim1": 2},
            {"shape": [64, 3, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [64, 3, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [64, 3, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [64, 3, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [64, 4, 49, 32], "dim0": -2, "dim1": -1},
            {"shape": [64, 4, 49, 32], "dim0": 1, "dim1": 2},
            {"shape": [64, 4, 64, 32], "dim0": -2, "dim1": -1},
            {"shape": [64, 4, 64, 32], "dim0": 1, "dim1": 2},
            {"shape": [8, 100, 32], "dim0": -2, "dim1": -1},
            {"shape": [8, 100, 32], "dim0": 0, "dim1": 1},
            {"shape": [8, 920, 32], "dim0": -2, "dim1": -1},
            {"shape": [8, 920, 32], "dim0": 0, "dim1": 1},
            {"shape": [920, 8, 32], "dim0": 0, "dim1": 1},
        ],
        "dtype": [ttnn.bfloat16, ttnn.int32],
        "layout": [ttnn.ROW_MAJOR_LAYOUT, ttnn.TILE_LAYOUT],
    }
}


def invalidate_vector(test_vector) -> Tuple[bool, Optional[str]]:
    if test_vector["layout"] == ttnn.ROW_MAJOR_LAYOUT:
        if test_vector["dtype"] == ttnn.bfloat8_b:
            return True, "bfloat8_b not supported with ROW_MAJOR_LAYOUT"

    return False, None


def random_torch_tensor(dtype, shape):
    if dtype == ttnn.uint16:
        return torch.randint(0, 100, shape).to(torch.int16)
    if dtype == ttnn.int32:
        return torch.randint(-(2**31), 2**31, shape, dtype=torch.int32)
    if dtype == ttnn.uint32:
        return torch.randint(0, 2**31, shape, dtype=torch.int32)
    return torch.rand(shape).bfloat16().float()


def run(
    transpose_specs,
    dtype,
    layout,
    *,
    device,
):
    torch_input_tensor = random_torch_tensor(dtype, transpose_specs["shape"])
    torch_output_tensor = torch.transpose(torch_input_tensor, transpose_specs["dim0"], transpose_specs["dim1"])

    ttnn_input_tensor = ttnn.from_torch(torch_input_tensor, device=device, dtype=dtype, layout=layout)

    start_time = start_measuring_time()
    ttnn_output = ttnn.transpose(ttnn_input_tensor, transpose_specs["dim0"], transpose_specs["dim1"])
    e2e_perf = stop_measuring_time(start_time)

    ttnn_output_tensor = ttnn.to_torch(ttnn_output)
    return [check_with_pcc(torch_output_tensor, ttnn_output_tensor, 0.9999), e2e_perf]


@pytest.mark.parametrize("transpose_specs", parameters["nightly"]["transpose_specs"])
@pytest.mark.parametrize("dtype", parameters["nightly"]["dtype"])
@pytest.mark.parametrize("layout", parameters["nightly"]["layout"])
def test_run(
    transpose_specs,
    dtype,
    layout,
    *,
    device,
):
    return run(
        transpose_specs,
        dtype,
        layout,
        device=device,
    )
